#include <allegro.h>
#include <stdio.h>
#include "richard.h"


#define nb 2


int main() {

	BITMAP *Buffer;
	BITMAP *Background=NULL;
	richard r;

	/* General initialization function */
	allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}

	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	//loading Richard
	load_richard(&r);
	//loading background
	Background=load_bitmap("../graphs/cave.bmp", NULL);

	//init position & direction
	init_richard(&r);

	while (!key[KEY_ESC]) {
		//vider le buffer
		clear_bitmap(Buffer);
		//Deplacement Richard
		deplacement(&r,Background);
		//drawing background
		draw_b(Background,Buffer);
		//drawing mario
		draw(r,Buffer);
		//blit Buffer to screen
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

	}
	//destroy Mario
	destroy_richard(&r);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);
}
END_OF_MAIN();
